package com.ruoyi.supervise.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.supervise.domain.IGMCompanyCreditRank;
import com.ruoyi.supervise.domain.IGMCompanyStageRank;
import com.ruoyi.supervise.domain.IGMPersonCreditRank;
import com.ruoyi.supervise.domain.IGMPersonStageRank;
import com.ruoyi.supervise.mapper.IntegrityEvaluationMapper;
import com.ruoyi.supervise.service.IIntegrityEvaluationService;

import cn.hutool.core.util.StrUtil;


/**
 * @ClassName: IIntegrityEvaluationService
 * @Description: 诚信评价管理impl
 * @Author wtj
 * @DateTime 2020年5月12日 下午4:26:18
 */
@Service
@DataSource(value = DataSourceType.SLAVE)
public class IntegrityEvaluationServiceImpl implements IIntegrityEvaluationService 
{
    @Autowired
    private IntegrityEvaluationMapper integrityEvaluationMapper;

	@Override
	public List<IGMCompanyCreditRank> selectIGMCompanyCreditRankList(IGMCompanyCreditRank igmccr) {
		if(!StringUtils.isEmpty(igmccr.getEvaluationObject())) {
			if(StrUtil.containsAny(igmccr.getEvaluationObject(), "|")) {
				String[] subStr=StrUtil.split(igmccr.getEvaluationObject(), "|");
				igmccr.setProfessional(subStr[0]);
				igmccr.setQualificationSequence(subStr[1]);
			}else {
				igmccr.setQualificationType(igmccr.getEvaluationObject());
			}
		}
		List<IGMCompanyCreditRank> igmccrList = integrityEvaluationMapper.selectIGMCompanyCreditRankList(igmccr);
		if(!StringUtils.isEmpty(igmccrList)) {
			for(IGMCompanyCreditRank ccr:igmccrList) {
				if(ccr.getQualificationType().equals("工程监理企业")) {
					ccr.setEvaluationObject(ccr.getProfessional()+StrUtil.subWithLength(ccr.getQualificationSequence().trim(), 0, ccr.getQualificationSequence().length()-4)+"企业");
				}else if(ccr.getQualificationType().equals("施工企业")) {
					ccr.setEvaluationObject(ccr.getProfessional()+ccr.getQualificationSequence()+"企业");
				}else {
					ccr.setEvaluationObject(ccr.getQualificationType());
				}
			}
		}
		return igmccrList;
	}

	@Override
	public List<IGMCompanyStageRank> selectIGMCompanyStageRankList(IGMCompanyStageRank igmcsr) {
		if(!StringUtils.isEmpty(igmcsr.getEvaluationObject())) {
			if(StrUtil.containsAny(igmcsr.getEvaluationObject(), "|")) {
				String[] subStr=StrUtil.split(igmcsr.getEvaluationObject(), "|");
				igmcsr.setProfessional(subStr[0]);
				igmcsr.setQualificationSequence(subStr[1]);
			}else {
				igmcsr.setQualificationType(igmcsr.getEvaluationObject());
			}
		}
		List<IGMCompanyStageRank> igmcsrList = integrityEvaluationMapper.selectIGMCompanyStageRankList(igmcsr);
		if(!StringUtils.isEmpty(igmcsrList)) {
			for(IGMCompanyStageRank csr:igmcsrList) {
				if(csr.getQualificationType().equals("工程监理企业")) {
					csr.setEvaluationObject(csr.getProfessional()+StrUtil.subWithLength(csr.getQualificationSequence().trim(), 0, csr.getQualificationSequence().length()-4)+"企业");
				}else if(csr.getQualificationType().equals("施工企业")) {
					csr.setEvaluationObject(csr.getProfessional()+csr.getQualificationSequence()+"企业");
				}else {
					csr.setEvaluationObject(csr.getQualificationType());
				}
			}
		}
		return igmcsrList;
	}

	@Override
	public List<IGMPersonCreditRank> selectIGMPersonCreditRankList(IGMPersonCreditRank igmpcr) {
		List<IGMPersonCreditRank> igmpcrList = integrityEvaluationMapper.selectIGMPersonCreditRankList(igmpcr);
		return igmpcrList;
	}

	@Override
	public List<IGMPersonStageRank> selectIGMPersonStageRankList(IGMPersonStageRank igmpsr) {
		// TODO Auto-generated method stub
		return integrityEvaluationMapper.selectIGMPersonStageRankList(igmpsr);
	}
}
